package com.sgb.kjwl.view.ui.activity.material.hall;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.github.dfqin.grantor.PermissionListener;
import com.github.dfqin.grantor.PermissionsUtil;
import com.google.android.material.tabs.TabLayout;
import com.sgb.alimaplibrary.MarkerEntity;
import com.sgb.alimaplibrary.widget.MapMarkerView;
import com.sgb.kjwl.AppFragment;
import com.sgb.link.utils.PickCateType;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.NewFragmentPickHallBinding;
import com.sgb.kjwl.di.home.DaggerHomeFragComponent;
import com.sgb.kjwl.di.home.HomeFragModule;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.TenderListEntity;
import com.sgb.alimaplibrary.SelectAddressActivity;
import com.sgb.kjwl.view.ui.activity.pick.TenderDetailsActivity3;
import com.sgb.kjwl.view.ui.adapter.pick.PickHallBidingAdapter;
import com.sgb.kjwl.view.widget.CommonCategoryFilterPopWindow;
import com.sgb.kjwl.view.widget.PickAreaPopWindow;
import com.sgb.link.view.widget.PickCityPopWindow;
import com.sgb.kjwl.view.widget.PickHallBidingPopWindow;
import com.sgb.kjwl.view.widget.pick.PickChooseLeftDialog2;
import com.sgb.kjwl.view.widget.pick.PickMapPopWindow;
import com.sgb.zhaocai.utils.PickCopyUtils;
import com.swgk.core.util.PickSelectTextEntity;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * 需求大厅--招标大厅
 */
@Deprecated
public class PickHallFragment extends AppFragment implements PickChooseLeftDialog2.DialogCallBackImpl {

    private NewFragmentPickHallBinding binding;
    private PickHallBidingAdapter pickingAdapter;

    private CommonCategoryFilterPopWindow categoryFilterPopWindow;
    private PickHallBidingPopWindow statusPopWindow;
    private PickHallBidingPopWindow moneyPopWindow;

    private PickHallBidingPopWindow typePopWindow;
    private PickHallBidingPopWindow applyPopWindow;
    private PickAreaPopWindow addrPopWindow;
    private PickCityPopWindow pickDistancePopWindow;
    private PickHallBidingPopWindow pickSortPopWindow;

    @Inject
    PickHallModle model;

    private List<PickSelectEntity> typeDatas = new ArrayList<>();
    private List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> categoryDatas = new ArrayList<>();
    private List<PickSelectEntity> sortData = new ArrayList<>();

    //省
    private String areacode;
    //地区
    private String citysNo = "";
    //类型
    private String typeNo = "0";

    //报名类型 2.9版
    private String tenderApplyNo = "";
    //金额
    private String moneyNo = "";
    //状态(1、待招标,2、招标中,3、评标中,4、招标结束,5、废标,6、再次招标,7、流标,8、待报名,9、报名中,10、资格审查中)
    private String statusNo = "";
    private int page = 1;
    private boolean isLoadMore = false;
    //搜索关键字
    private String searchName = "";
    private String goodsType;
    private String distance = "1000";
    //排序类型
    private String sortType = "1";

    private boolean isMap = true;
    private Double latitude; //纬度
    private Double longitude; //经度

    private PickMapPopWindow pickMapPopWindow;
    private List<TenderListEntity> tenderListEntityMapList = new ArrayList<>();
    List<MarkerEntity> markerEntityList = new ArrayList<>();
    private boolean isHandLocation = false; //手动定位
    private boolean isLocation = false; //重新定位

    //招标类型
    private String tenderTypeNo = "";
    private int tabPosition = 0;

    public static final String FROM_WHERE = "FROM_WHERE";

    public static PickHallFragment newInstance(String fromWhere) {
        PickHallFragment fragment = new PickHallFragment();
        Bundle bundle = new Bundle();
        bundle.putString(FROM_WHERE, fromWhere);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerHomeFragComponent
                .builder()
                .appComponent(appComponent)
                .homeFragModule(new HomeFragModule(this))
                .build()
                .inject(this);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.new_fragment_pick_hall, container, false);
        if ("1".equals(getArguments().get(FROM_WHERE))) {
            binding.include.includeLayout.setVisibility(View.VISIBLE);
        } else {
            binding.include.includeLayout.setVisibility(View.GONE);
        }
        binding.mMapView.initMap(savedInstanceState, getLifecycle(), 40, new MapMarkerView.CallBack() {
            @Override
            public void onLocation(Double Lat, Double Log, String string) {
                MLog.e("api", "onLocation" + string);
                isHandLocation = false;
                binding.tvAddressName.setText(string);

                longitude = Log;
                latitude = Lat;
                model.findTenderMapPage(typeNo, statusNo, tenderApplyNo, goodsType, latitude, longitude, distance, searchName, false, tenderTypeNo);

                if (isLocation) {
                    binding.relNoMap.setVisibility(View.GONE);
                    binding.relLocation.setVisibility(View.VISIBLE);
                    isLocation = false;
                }
            }

            @Override
            public void onMarkerClick(int pos, String title) {
            }

            @Override
            public void onMarkerClick(int pos, String title, Marker marker) {
                super.onMarkerClick(pos, title, marker);
                setMarkerBig(pos, marker, true);
                showMapPopWindow(pos);
            }

        });
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
    }

    private void initView() {
        initChooseDialog();
        binding.include.rightView.setText("发布");
        binding.include.tvSearch.setText("搜索");
        binding.include.etView.setHint("搜索招标名称");
        binding.include.tvSearchDelete.setOnClickListener(this);
        binding.include.tvSearchDelete.setVisibility(View.VISIBLE);
        binding.include.rightView.setOnClickListener(this);
        binding.include.tvSearch.setOnClickListener(this);
        searchName = "";
        binding.tvStatus.setOnClickListener(this);
        binding.tvMoney.setOnClickListener(this);
        binding.tvAddr.setOnClickListener(this);
//        binding.tvType.setOnClickListener(this);
        //新增类别
        binding.tvCategory.setOnClickListener(this);
        binding.tvSort.setOnClickListener(this);

        binding.ivListVsMak.setOnClickListener(this);
        binding.tvDistance.setOnClickListener(this);
        binding.tvLocation.setOnClickListener(this);
        binding.handLocation.setOnClickListener(this);
        binding.getLocation.setOnClickListener(this);
        binding.ivChoose.setOnClickListener(this);
        binding.tvApply.setOnClickListener(this);
        binding.ivLocationRight.setOnClickListener(this);

        categoryFilterPopWindow = new CommonCategoryFilterPopWindow(getActivity(),false);
        categoryFilterPopWindow.setBgView(binding.bgPopGrayLayout);
        categoryFilterPopWindow.setResultListener(new CommonCategoryFilterPopWindow.Listener() {
            @Override
            public void setResultListener(String text, String result, String typeNo) {

            }

            @Override
            public void setResetResultListener() {
                resetCategoryFilterPopWindow();
            }
        });
        categoryFilterPopWindow.setCategoryCallBack(new CommonCategoryFilterPopWindow.CategoryCallBack() {
            @Override
            public void resultPosition(String posName1, String posName2, String posName3, int pos1, int pos2, int pos3) {
                clearOtherDataInfo(PickCateType.TYPE_CATEGORY_0);
                updateChooseStatus(PickCateType.TYPE_CATEGORY_0, 0);
                if (pos1 > 0) {
                    updateChooseStatus(PickCateType.TYPE_CATEGORY_0, pos1);
                    if (pos2 > 0) {
                        List<PickSelectEntity> list2 = new ArrayList<>();
                        List<PickSelectEntity<List<PickSelectEntity>>> cate1 = categoryDatas.get(pos1).getChildren();
                        if (cate1 != null && cate1.size() > 0) {
                            list2.addAll(cate1);
                        }
                        refreshDataInfo(PickCateType.TYPE_CATEGORY_1, "", list2);
                        updateChooseStatus(PickCateType.TYPE_CATEGORY_1, pos2);
                        if (pos3 > 0) {
                            List<PickSelectEntity> list3 = new ArrayList<>();
                            List<PickSelectEntity> cate2 = categoryDatas.get(pos1).getChildren().get(pos2).getChildren();
                            if (cate2 != null && cate2.size() > 0) {
                                list3.addAll(cate2);
                            }
                            refreshDataInfo(PickCateType.TYPE_CATEGORY_2, "", list3);
                            updateChooseStatus(PickCateType.TYPE_CATEGORY_2, pos3);
                        }
                    }
                }
                initFilterData();
            }
        });
        categoryFilterPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                int pos1 = getItemPos(PickCateType.TYPE_CATEGORY_0);
                updateChooseTextStatus(binding.tvCategory, pos1 > 0 ? 1 : 0, null);
            }
        });

//        // 招标方式
//        typePopWindow = new PickHallBidingPopWindow(getContext());
//        typePopWindow.setBgView(binding.bgPopGrayLayout);
//        typePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
//            @Override
//            public void result(Object key1, Object key2, Object key3) {
//                updateChooseStatus(PickCateType.TYPE_BIDDING, (Integer) key3);
//                initFilterData();
//            }
//        });
//        typePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
//            @Override
//            public void disMiss() {
//                int value = getItemPos(PickCateType.TYPE_BIDDING);
//                updateChooseTextStatus(binding.tvType, value > 0 ? 1 : 0, null);
//            }
//        });

        // 报名方式
        applyPopWindow = new PickHallBidingPopWindow(getActivity());
        applyPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                updateChooseStatus(PickCateType.TYPE_SIGN, (Integer) key3);
                initFilterData();
            }
        });
        applyPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                int value = getItemPos(PickCateType.TYPE_SIGN);
                updateChooseTextStatus(binding.tvApply, value > 0 ? 1 : 0, null);
            }
        });

        // 招标状态
        statusPopWindow = new PickHallBidingPopWindow(getActivity());
        statusPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object type, Object key2, Object key3) {
                updateChooseStatus(PickCateType.TYPE_BIDDING_STATUS, (Integer) key3);
                initFilterData();
            }
        });
        statusPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                int value = getItemPos(PickCateType.TYPE_BIDDING_STATUS);
                updateChooseTextStatus(binding.tvStatus, value > 0 ? 1 : 0, null);
            }
        });

        // 概算金额
        moneyPopWindow = new PickHallBidingPopWindow(getContext());
        moneyPopWindow.setBgView(binding.bgPopGrayLayout);
        moneyPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                updateChooseStatus(PickCateType.TYPE_MONEY, (Integer) key3);
                initFilterData();
            }
        });
        moneyPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                int value = getItemPos(PickCateType.TYPE_MONEY);
                updateChooseTextStatus(binding.tvMoney, value > 0 ? 1 : 0, null);
            }
        });

        // 省市
        addrPopWindow = new PickAreaPopWindow(getActivity());
        addrPopWindow.isVisibleBottomLayout(true);
        addrPopWindow.setAreaListener(new PickAreaPopWindow.AreaListener() {
            @Override
            public void onAreaResult(int pos1, int pos2, List<PickSelectEntity> list) {
                clearOtherDataInfo(PickCateType.TYPE_PROVINCE);
                updateChooseStatus(PickCateType.TYPE_PROVINCE, 0);
                updateChooseStatus(PickCateType.TYPE_CITY, 0);
                if (pos1 > 0) {
                    updateChooseStatus(PickCateType.TYPE_PROVINCE, pos1);
                    if (pos2 > 0) {
                        refreshDataInfo(PickCateType.TYPE_CITY, "", list);
                        updateChooseStatus(PickCateType.TYPE_CITY, pos2);
                    }
                } else {
                    clearOtherDataInfo(PickCateType.TYPE_PROVINCE);
                }
                initFilterData();
            }
        });
        addrPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                int pos1 = getItemPos(PickCateType.TYPE_PROVINCE);
                updateChooseTextStatus(binding.tvAddr, pos1 > 0 ? 1 : 0, null);
            }
        });
        addrPopWindow.setiButtonClick(new PickAreaPopWindow.IButtonClick() {
            @Override
            public void next(String no) {
                List<PickSelectEntity> itemData = getItemData(PickCateType.TYPE_CITY);
                int itemPos = getItemPos(PickCateType.TYPE_CITY);
                if (itemData == null || itemData.size() == 0) {
                    model.getCityData(no, false);
                } else {
                    addrPopWindow.setCityData(itemData, itemPos);
                }
            }
        });

        binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                tabPosition = tab.getPosition();
                typeNo = typeDatas.get(tabPosition).getNo();
                showChooseView(tabPosition);
                pickingAdapter.setType(typeNo);
                sortType = "1";
                updateChooseTextStatus(binding.tvSort, Integer.valueOf(sortType) == 1 ? 0 : 1, "综合排序");
                pickSortPopWindow.setDefItem();
                mFilters.clear();
                clearOtherDataInfo(PickCateType.TYPE_CATEGORY_0);
                clearOtherDataInfo(PickCateType.TYPE_PROVINCE);
                loadData(mData, mFilters);

                if (tab != null && tab.getCustomView() != null) {
                    TextView tabSelect = tab.getCustomView().findViewById(R.id.tv_tab_item_textview);
                    tabSelect.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    tabSelect.setTextColor(getResources().getColor(R.color.new_blue));
                    tabSelect.invalidate();
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

                if (tab != null && tab.getCustomView() != null) {
                    TextView tabSelect = tab.getCustomView().findViewById(R.id.tv_tab_item_textview);
                    tabSelect.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                    tabSelect.setTextColor(getResources().getColor(R.color.color_tab_one));
                    tabSelect.invalidate();
                }

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        //距离
        pickDistancePopWindow = new PickCityPopWindow(getContext());
        pickDistancePopWindow.setBgView(binding.bgPopGrayLayout);
        pickDistancePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                updateChooseStatus(PickCateType.TYPE_DISTANCE, (Integer) key3);
                initFilterData();
            }
        });
        pickDistancePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                int value = getItemPos(PickCateType.TYPE_DISTANCE);
                updateChooseTextStatus(binding.tvDistance, value > 0 ? 1 : 0, null);
            }
        });

        //排序方式
        pickSortPopWindow = new PickHallBidingPopWindow(getContext());
        pickSortPopWindow.setBgView(binding.bgPopGrayLayout);
        pickSortPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                String name = ((PickSelectEntity) key1).getProjectscale();
                sortType = ((PickSelectEntity) key1).getNo();
                updateChooseTextStatus(binding.tvSort, (Integer) key3, name);
                initFilterData();
            }
        });
        pickSortPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                updateChooseTextStatus(binding.tvSort, Integer.valueOf(sortType) == 1 ? 0 : 1, null);
            }
        });

        //初始化筛选
//        pickMapPopWindow = new PickMapPopWindow(getActivity(), 3, new PickMapPopWindow.CallBack() {
//            @Override
//            public void onMoreData(boolean more) {
//                model.findTenderMapPage(typeNo, statusNo, tenderApplyNo, goodsType, latitude, longitude, distance, searchName, false, tenderTypeNo);
//            }
//
//            @Override
//            public void onDismiss() {
//                setMarkerBig(0, null, false);
//            }
//
//            @Override
//            public void onShowPosition(int position) {
//                String title = markerEntityList.get(position).getTitle();
//                if (title != null) {
//                    Marker marker = binding.mMapView.getMapScreenMarker(title);
//                    if (marker != null) {
//                        setMarkerBig(position, marker, true);
//                    }
//                }
//            }
//
//            @Override
//            public void onItemClick(TenderListEntity tenderListEntity) {
//                TenderDetailsActivity3.start(getActivity(), tenderListEntity.getId(), 0);
//            }
//        });
        pickMapPopWindow.setBgView(binding.recyclerView);

        if (pickingAdapter == null) {
            pickingAdapter = new PickHallBidingAdapter(getActivity(), null);
        }
        DividerItemDecoration divider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.shape_list_divide2));
        binding.recyclerView.addItemDecoration(divider);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        binding.recyclerView.setLayoutManager(layoutManager);
        binding.recyclerView.setAdapter(pickingAdapter);
        binding.recyclerView.setLoadingMoreEnabled(true);
        binding.recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                initFilterData();
            }

            @Override
            public void onLoadMore() {
                isLoadMore = true;
                page = page + 1;
                model.getList(citysNo, typeNo, moneyNo, statusNo, page, searchName, tenderApplyNo, areacode, goodsType, tenderTypeNo, sortType);
            }
        });

        pickingAdapter.setOnItemClick(new AdapterOnItemClick<TenderListEntity>() {
            @Override
            public void onItemClick(TenderListEntity tenderListEntity, int position) {
                TenderDetailsActivity3.start(getActivity(), tenderListEntity.getId(), 0);

            }
        });
        pickingAdapter.onIChildClick(new PickHallBidingAdapter.IChildClick() {
            @Override
            public void onClick(TenderListEntity tenderListEntity) {
                TenderDetailsActivity3.start(getActivity(), tenderListEntity.getId(), 0);

            }
        });
    }

    private void resetCategoryFilterPopWindow() {
        clearOtherDataInfo(PickCateType.TYPE_CATEGORY_0);
        getCategoryAllList();
    }

    private void initData() {
        model.getProvinceData();
        model.getFilterTypeData();
        model.getFilterStatusData();
        model.getMoneyTypeData();
        model.getTenderNewTypeList();
        model.getSortTypeData();

        //招标方式
//        String[] stringType = new String[]{"全部", "公开招标&1", "邀请招标&2"};
//        setPickTypeDatas(stringType);

        //距离筛选条件
        String[] strings = new String[]{"10", "20", "50", "100", "200", "500"};
        setDistanceDatas(strings);
        setMapOrList(isMap);

    }

    private void initFilterData() {
        if (isMap) {
            model.findTenderMapPage(typeNo, statusNo, tenderApplyNo, goodsType, latitude, longitude, distance, searchName, false, tenderTypeNo);
        } else {
            isLoadMore = false;
            page = 1;
            model.getList(citysNo, typeNo, moneyNo, statusNo, page, searchName, tenderApplyNo, areacode, goodsType, tenderTypeNo, sortType);
        }
    }

    private void showMapAndPopWindow() {
        showPositionMap(0);
        showMapPopWindow(0);
    }

    private void showPositionMap(int position) {
        String title = markerEntityList.get(position).getTitle();
        if (title != null) {
            Marker marker = binding.mMapView.getMapScreenMarker(title);
            if (marker != null) {
                setMarkerBig(position, marker, true);
            }
        }
    }

    private void getCategoryAllList() {
        model.getTenderGoodsCategoryAllList(typeNo);
    }
//需要改造
//    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
//    public void onMessageEvent(PickEvent event) {
//        if (event.getMessageTag() == EventConstant.EVENT_PICK_HALL_SEARCH_DATA) {
//            searchName = (String) event.getMessageData();
//            initFilterData();
//        } else if (event.getMessageTag() == EventConstant.EVENT_PICK_HALL_SEARCH_DATA_UPDATA) {
//
//            Double longitudeHand = event.getLongitude();
//            Double latitudeHand = event.getLatitude();
//            binding.tvAddressName.setText(event.getMessageData().toString());
//
//            if (latitude == null && longitude == null) {  //自动定位未获取到位置 第一次
//                if (latitudeHand != 0 || longitudeHand != 0) {  //手动定位获取到位置
//                    isHandLocation = true;
//                    latitude = latitudeHand;
//                    longitude = longitudeHand;
//                    binding.relNoMap.setVisibility(View.GONE);
//                    binding.relLocation.setVisibility(View.VISIBLE);
//                    binding.mMapView.setVisibility(View.VISIBLE);
//                    binding.mMapView.setMyLocation(latitude, longitude, R.drawable.location);
//                } else {
//                    binding.handLocation.setBackgroundResource(R.drawable.map_text_bg_gray);
//                    binding.handLocation.setTextColor(getResources().getColor(R.color.color_999999));
//                }
//            } else {
//                if (!latitudeHand.equals(latitude) || !longitudeHand.equals(longitude)) {
//                    latitude = latitudeHand;
//                    longitude = longitudeHand;
//                    binding.mMapView.setMyLocation(latitude, longitude, R.drawable.location);
//                } else {
//                    binding.relNoMap.setVisibility(View.GONE);
//                }
//            }
//            initFilterData();
//
//        }
//    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.right_view:
                MToast.showLongToast(getActivity(), "移动端暂不支持发布招标，请前往pc端“经营帮/用户中心/招采 经营”发布招标信息", Gravity.CENTER);
                break;
            case R.id.tv_search:
                if (!TextUtils.isEmpty(binding.include.etView.getText().toString())) {
                    searchName = binding.include.etView.getText().toString();
                    initFilterData();
                }
                break;
            case R.id.tv_search_delete:
                binding.include.etView.setText("");
                initFilterData();
                break;
            case R.id.tv_money:
                List<PickSelectEntity> moneyDatas = getItemData(PickCateType.TYPE_MONEY);
                if (moneyDatas != null && moneyDatas.size() > 0) {
                    updateChooseTextStatus(binding.tvMoney, TextUtils.isEmpty(moneyNo) ? -1 : -2, null);
                    moneyPopWindow.showPopwindow(binding.tvMoney, 0, 0);
                    int value = getItemPos(PickCateType.TYPE_MONEY);
                    moneyPopWindow.updateData(value, getItemData(PickCateType.TYPE_MONEY));
                }
                break;
            case R.id.tv_addr:
                showProvincePopWindow();
                break;
//            case R.id.tv_type:  //招标方式
//                List<PickSelectEntity> tenderTypeDatas = getItemData(PickCateType.TYPE_BIDDING);
//                if (tenderTypeDatas != null && tenderTypeDatas.size() > 0) {
//                    updateChooseTextStatus(binding.tvType, TextUtils.isEmpty(tenderTypeNo) ? -1 : -2, null);
//                    typePopWindow.showPopwindow(binding.tvType, 0, 0);
//                    int value = getItemPos(PickCateType.TYPE_BIDDING);
//                    typePopWindow.updateData(value, getItemData(PickCateType.TYPE_BIDDING));
//                }
//                break;
            case R.id.tv_apply: //报名方式
                List<PickSelectEntity> applyDatas = getItemData(PickCateType.TYPE_SIGN);
                if (null != applyDatas && applyDatas.size() > 0) {
                    updateChooseTextStatus(binding.tvApply, TextUtils.isEmpty(tenderApplyNo) ? -1 : -2, null);
                    applyPopWindow.showPopwindow(binding.tvApply, 0, 0);
                    int value = getItemPos(PickCateType.TYPE_SIGN);
                    applyPopWindow.updateData(value, getItemData(PickCateType.TYPE_SIGN));
                }
                break;
            case R.id.tv_status:   //招标状态
                List<PickSelectEntity> statusDatas = getItemData(PickCateType.TYPE_BIDDING_STATUS);
                if (statusDatas != null && statusDatas.size() > 0) {
                    updateChooseTextStatus(binding.tvStatus, TextUtils.isEmpty(statusNo) ? -1 : -2, null);
                    statusPopWindow.showPopwindow(binding.tvStatus, 0, 0);
                    int value = getItemPos(PickCateType.TYPE_BIDDING_STATUS);
                    statusPopWindow.updateData(value, getItemData(PickCateType.TYPE_BIDDING_STATUS));
                }
                break;
            case R.id.tv_category:
                if (null != categoryDatas && categoryDatas.size() > 0) {
                    updateChooseTextStatus(binding.tvCategory, TextUtils.isEmpty(goodsType) ? -1 : -2, null);
                    categoryFilterPopWindow.showPopwindow(binding.tvCategory);
                    if (!TextUtils.isEmpty(typeNo)) {
                        categoryFilterPopWindow.setData(categoryDatas, Integer.parseInt(typeNo), typeDatas.get(tabPosition).getProjectscale());
                    }
                    int pos1 = getItemPos(PickCateType.TYPE_CATEGORY_0);
                    int pos2 = getItemPos(PickCateType.TYPE_CATEGORY_1);
                    int pos3 = getItemPos(PickCateType.TYPE_CATEGORY_2);
                    categoryFilterPopWindow.setCateData(pos1, pos2, pos3);
                }
                break;
            case R.id.iv_list_vs_mak://地图和列表切换
                setMapOrList(true);
                break;
            case R.id.tv_distance://距离筛选控件
                showDistancePopWindow();
                break;
            case R.id.tv_location: //手动定位
            case R.id.hand_location:
                //手动定位--不能获取位置信息时
                Intent intent = new Intent();
                intent.setClass(getActivity(), SelectAddressActivity.class);
                intent.putExtra(SelectAddressActivity.TITLE, "我的位置");
                intent.putExtra(SelectAddressActivity.SAVE_TEXT, "使用该定位地址");
                intent.putExtra(SelectAddressActivity.SHOWLOCATION, "SHOWLOCATION");
                intent.putExtra(SelectAddressActivity.LATITUDE, latitude);
                intent.putExtra(SelectAddressActivity.LONGTITUDE, longitude);
                startActivityForResult(intent, 255);

                if (pickMapPopWindow != null && pickMapPopWindow.isShowing()) {
                    pickMapPopWindow.dismiss();
                }

                binding.getLocation.setBackgroundResource(R.drawable.map_text_bg_gray);
                binding.getLocation.setTextColor(getResources().getColor(R.color.color_input_hint));
                binding.handLocation.setBackgroundResource(R.drawable.map_text_bg_blue);
                binding.handLocation.setTextColor(getResources().getColor(R.color.color_5792FD));

                break;
            case R.id.get_location:
                //重新获取定位--不能获取位置信息时
                if (!isLocationEnabled()) {
                    Intent intent1 = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivity(intent1);
                } else {
                    if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                            ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        PermissionsUtil.requestPermission(getActivity(), new PermissionListener() {
                            @Override
                            public void permissionGranted(@NonNull String[] permissions) {
                                binding.relNoMap.setVisibility(View.GONE);
                                binding.relLocation.setVisibility(View.VISIBLE);
                                isMap = true;
                                initFilterData();
                            }

                            @Override
                            public void permissionDenied(@NonNull String[] permissions) {
                                MToast.showLongToast(getActivity(), "请先允许“经营帮”获取此设备的位置信息");
                            }
                        }, android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION);
                    }
                }
                break;
            case R.id.iv_choose:
                if (!TextUtils.isEmpty(typeNo)) {
                    mLeftDialog2.initCategory(Integer.parseInt(typeNo), isMap,false);
                    mLeftDialog2.initData(mData, mFilters);
                    mLeftDialog2.showDialog();
                }
                break;
            case R.id.tv_sort:
                showSortPopWindow();
                break;
            case R.id.iv_location_right:
                if (latitude != 0 && longitude != 0) {
                    LatLng latLng = new LatLng(latitude, longitude);
                    binding.mMapView.zoomToSpan(latLng);
                }
                break;
        }
    }

    /**
     * 排序
     */
    private void showSortPopWindow() {
        updateChooseTextStatus(binding.tvSort, Integer.valueOf(sortType) == 1 ? -1 : -2, null);
        pickSortPopWindow.showPopwindow(binding.tvSort);
        pickSortPopWindow.setData(sortData, false);
    }

    /**
     * 省份
     */
    private void showProvincePopWindow() {
        updateChooseTextStatus(binding.tvAddr, TextUtils.isEmpty(areacode) && TextUtils.isEmpty(citysNo) ? -1 : -2, null);
        addrPopWindow.showPopwindow(binding.tvAddr);
        int value = getItemPos(PickCateType.TYPE_PROVINCE);
        addrPopWindow.setData(getItemData(PickCateType.TYPE_PROVINCE), value);
        if (value > 0) {
            addrPopWindow.setCityData(getItemData(PickCateType.TYPE_CITY), getItemPos(PickCateType.TYPE_CITY));
        }
    }

    public void fullScroll() {
        binding.recyclerView.getLayoutManager().scrollToPosition(0);
    }

    private void setDistanceDatas(String[] strings) {
        PickSelectEntity all = new PickSelectEntity();
        all.setNo("1000");
        all.setProjectscale("全部");
        all.setCheck(true);
        List<PickSelectEntity> distanceDates = new ArrayList<>();
        distanceDates.add(0, all);
        for (String s : strings) {
            PickSelectEntity pickSelectEntity = new PickSelectEntity();
            pickSelectEntity.setNo(s);
            pickSelectEntity.setProjectscale(s + "km以内");
            distanceDates.add(pickSelectEntity);
        }
        refreshDataInfo(PickCateType.TYPE_DISTANCE, "距离", distanceDates);

    }

    public void setSortDatas(List<PickSelectEntity> datas) {
        sortData.clear();
        sortData.addAll(datas);
    }

    private void setPickTypeDatas(String[] strings) {
        List<PickSelectEntity> tenderTypeDatas = new ArrayList<>();
        for (String s : strings) {
            PickSelectEntity pickSelectEntity = new PickSelectEntity();
            if (s.contains("&")) {
                String[] splitText = s.split("&");
                pickSelectEntity.setNo(splitText[1]);
                pickSelectEntity.setProjectscale(splitText[0]);
            } else {
                pickSelectEntity.setNo("");
                pickSelectEntity.setProjectscale(s);
            }
            tenderTypeDatas.add(pickSelectEntity);
        }
        refreshDataInfo(PickCateType.TYPE_BIDDING, "招标方式", tenderTypeDatas);
    }


    /**
     * 地图和列表模式切换
     */
    private void setMapOrList(boolean isClick) {
        isMap = !isMap;
        if (isMap) { //当是地图，界面切换成列表样式
            setViewIsMap();
            if (latitude == null && longitude == null) {
                if (!isLocationEnabled()) {
                    binding.relLocation.setVisibility(View.GONE);
                    binding.relNoMap.setVisibility(View.VISIBLE);
                    return;
                }
                if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                        ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    binding.relLocation.setVisibility(View.GONE);
                    binding.relNoMap.setVisibility(View.VISIBLE);
                    return;
                }
            }
            if (isHandLocation) {  //手动定位成功
                if (isLocationEnabled()) {
                    latitude = null;
                    longitude = null;
                }
            }
            binding.relLocation.setVisibility(View.VISIBLE);

        } else { //当是列表，将界面切换成地图模式
            if (pickMapPopWindow != null && pickMapPopWindow.isShowing()) {
                pickMapPopWindow.dismiss();
            }
            setViewIsList();
            binding.relLocation.setVisibility(View.GONE);
            if (isClick) {
                binding.relNoMap.setVisibility(View.GONE);
            }
        }
        showChooseView(tabPosition);
        initFilterData();
    }

    /**
     * 将界面切换成地图模式
     */
    private void setViewIsMap() {
        binding.mMapView.setVisibility(View.VISIBLE);
        binding.recyclerView.setVisibility(View.GONE);
        binding.ivListVsMak.setImageDrawable(getResources().getDrawable(R.drawable.bg_icon_list));
    }

    /**
     * 将界面切换成列表模式
     */
    private void setViewIsList() {
        binding.mMapView.setVisibility(View.GONE);
        binding.recyclerView.setVisibility(View.VISIBLE);
        binding.ivListVsMak.setImageDrawable(getResources().getDrawable(R.drawable.bg_icon_map));
    }

    /**
     * 距离筛选
     */
    private void showDistancePopWindow() {
        updateChooseTextStatus(binding.tvDistance, TextUtils.isEmpty(distance) ? -1 : -2, null);
        pickDistancePopWindow.showPopwindow(binding.tvDistance);
        int value = getItemPos(PickCateType.TYPE_DISTANCE);
        pickDistancePopWindow.setData(getItemData(PickCateType.TYPE_DISTANCE), value);
    }

    private void showMapPopWindow(int position) {
        if (!pickMapPopWindow.isShowing()) {
            pickMapPopWindow.showDownPopwindow(binding.tvAddr, true);
            pickMapPopWindow.backgroundAlpha(1f);
        }
        pickMapPopWindow.setData(tenderListEntityMapList, position);
        //点击外部区域不消失
        pickMapPopWindow.setFocusable(false);   //TODO 点击地图上的Marker时，列表显示，地图消失，需要检查下，只有在招标大厅里出现这个问题
        pickMapPopWindow.setOutsideTouchable(false);
    }

    public void showList(List<TenderListEntity> list) {
        binding.recyclerView.refreshComplete();
        if (isLoadMore) {
            binding.recyclerView.loadMoreComplete();
            if (list.size() > 0) {
                pickingAdapter.addDatas(list);
            } else {
                binding.recyclerView.setLoadingMoreEnabled(false);
            }
            binding.recyclerView.setVisibility(View.VISIBLE);
        } else {
            binding.recyclerView.refreshComplete();
            if (list.size() > 0) {
                binding.recyclerView.setVisibility(View.VISIBLE);
                binding.emptyView.setVisibility(View.GONE);
                pickingAdapter.setDatas(list);
                binding.recyclerView.setLoadingMoreEnabled(true);
            } else {
                pickingAdapter.setDatas(null);
                binding.recyclerView.setVisibility(View.GONE);
                binding.emptyView.setVisibility(View.VISIBLE);
            }
        }
    }


    public void setTypeDatas(List<PickSelectEntity> datas) {
        typeDatas.clear();
//        PickSelectEntity entity = new PickSelectEntity();
//        entity.setNo("0");
//        entity.setProjectscale("全部");
//        typeDatas.add(entity);
        typeDatas.addAll(datas);
        for (int i = 0; i < typeDatas.size(); i++) {
            binding.tabLayout.addTab(binding.tabLayout.newTab());
            binding.tabLayout.getTabAt(i).setCustomView(R.layout.tab_item_textview);
            TextView tv = binding.tabLayout.getTabAt(i).getCustomView().findViewById(R.id.tv_tab_item_textview);
            tv.setText(typeDatas.get(i).getProjectscale());
            if (i == 0) {
                tv.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                tv.setTextColor(getResources().getColor(R.color.new_blue));
            }
        }
        binding.tabLayout.getTabAt(1).select(); //默认选中某项放在加载viewpager之后
    }

    public void setStatusDatas(List<PickSelectEntity> datas) {
        List<PickSelectEntity> list = new ArrayList<>();
        for (PickSelectEntity entity : datas) {
            if (!entity.getProjectscale().equals("报名中") && !entity.getProjectscale().equals("再次招标")) {
                list.add(entity);
            }
        }
        refreshDataInfo(PickCateType.TYPE_BIDDING_STATUS, "招标状态", list);
    }

    public void setMoneyDatas(List<PickSelectEntity> datas) {
        refreshDataInfo(PickCateType.TYPE_MONEY, "概算金额", datas);
    }

    public void setProvinceDatas(List<PickSelectEntity> datas) {
        refreshDataInfo(PickCateType.TYPE_PROVINCE, "省份", datas);
    }

    public void setCityDatas(List<PickSelectEntity> datas, boolean isShowDialog) {
        PickSelectEntity entity = new PickSelectEntity();
        entity.setNo("");
        entity.setProjectscale("全部");
        datas.add(0, entity);
        if (isShowDialog) {
            mLeftDialog2.addEntity(PickCateType.TYPE_CITY, datas);
            mLeftDialog2.showDialog();
        } else {
            addrPopWindow.setCityData(datas, 0);
        }
    }

    public void setTenderTypeDatas(List<PickSelectEntity> datas) {
        refreshDataInfo(PickCateType.TYPE_SIGN, "报名方式", datas);
    }

    public void setTenderGoodsCategoryAllList(List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> datas) {
        categoryDatas.clear();
        categoryDatas.addAll(datas);
        if (categoryDatas.size() != 0) {
            categoryDatas.get(0).setCheck(true);
            List<PickSelectEntity> list = new ArrayList<>();
            list.addAll(categoryDatas);
            refreshDataInfo(PickCateType.TYPE_CATEGORY_0, "类别", list);
        }
    }


    private void setTextViewBg(TextView textView, int bg, int img, int textColor) {
        textView.setBackground(getResources().getDrawable(bg));
        Drawable drawable_n = getResources().getDrawable(img);
        drawable_n.setBounds(0, 0, drawable_n.getMinimumWidth(), drawable_n.getMinimumHeight());  //此为必须写的
        textView.setCompoundDrawables(null, null, drawable_n, null);
        textView.setTextColor(getResources().getColor(textColor));
    }

    public void showMapList(List<TenderListEntity> tenderListEntityList, boolean lastPage, boolean b) {
        if (tenderListEntityList == null || tenderListEntityList.size() == 0) {
            return;
        }
        if (!b) {
            markerEntityList.clear();
        }
        for (TenderListEntity tenderListEntityMap : tenderListEntityList) {
            if (!TextUtils.isEmpty(tenderListEntityMap.getLocalLat()) && !TextUtils.isEmpty(tenderListEntityMap.getLocalLng())) {
                LatLng latLng = new LatLng(Double.valueOf(tenderListEntityMap.getLocalLat()), Double.valueOf(tenderListEntityMap.getLocalLng()));
                MarkerEntity markerEntity;
                if (tenderListEntityMap.getStatus().equals("5")) {  //废标
                    markerEntity = new MarkerEntity(latLng, R.mipmap.zhao_gray, tenderListEntityMap.getId());
                } else {
                    markerEntity = new MarkerEntity(latLng, R.mipmap.zhao, tenderListEntityMap.getId());
                }
                markerEntity.setStatus(tenderListEntityMap.getStatus());
                markerEntityList.add(markerEntity);
            }
        }

        if (b) {
            binding.mMapView.addMarkerData(markerEntityList);
        } else {
            binding.mMapView.setMarkerData(markerEntityList);
        }
    }

    private void setMarkerBig(int pos, Marker marker, Boolean isBig) {
        for (MarkerEntity markerEntity : markerEntityList) {
            if (markerEntity.getStatus().equals("5")) {  //废标
                markerEntity.setIcon(R.mipmap.zhao_gray);
            } else {
                markerEntity.setIcon(R.mipmap.zhao);
            }
            if (isBig) {
                if (markerEntity.getTitle().equals(marker.getTitle())) {
                    if (markerEntity.getStatus().equals("5")) {  //废标
                        markerEntity.setIcon(R.mipmap.zhao_gray_big);
                    } else {
                        markerEntity.setIcon(R.mipmap.zhao_big);
                    }
                }
            }

        }
        binding.mMapView.setMarkerData(markerEntityList);
    }

    public void setbiddingListEntityMapList(List<TenderListEntity> list, boolean b) {
        if (list == null || list.size() == 0) {
            return;
        }
        if (b) {
            tenderListEntityMapList.addAll(list);
        } else {
            tenderListEntityMapList.clear();
            tenderListEntityMapList.addAll(list);
        }
        if (isMap) {
            showMapAndPopWindow();
        }
    }

    //用户是否打开系统定位服务
    public boolean isLocationEnabled() {
        int locationMode = 0;
        String locationProviders;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            try {
                locationMode = Settings.Secure.getInt(getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE);
            } catch (Settings.SettingNotFoundException e) {
                e.printStackTrace();
                return false;
            }
            return locationMode != Settings.Secure.LOCATION_MODE_OFF;
        } else {
            locationProviders = Settings.Secure.getString(getActivity().getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
            return !TextUtils.isEmpty(locationProviders);
        }

    }

    private PickChooseLeftDialog2 mLeftDialog2;
    // 数据集
    private SparseArray<PickSelectTextEntity> mData = new SparseArray<>();
    private SparseIntArray mFilters = new SparseIntArray();
    private SparseArray<String> nameArray = new SparseArray<>();

    private void initChooseDialog() {
        nameArray.put(PickCateType.TYPE_CATEGORY_0, "类别");
        nameArray.put(PickCateType.TYPE_CATEGORY_1, "类别1");
        nameArray.put(PickCateType.TYPE_CATEGORY_2, "类别2");
//        nameArray.put(PickCateType.TYPE_BIDDING, "招标方式");
        nameArray.put(PickCateType.TYPE_SIGN, "招标方式");
        nameArray.put(PickCateType.TYPE_BIDDING_STATUS, "招标状态");
        nameArray.put(PickCateType.TYPE_MONEY, "概算金额");
        nameArray.put(PickCateType.TYPE_SIGN_TIME, "报名结束时间");
        nameArray.put(PickCateType.TYPE_PROVINCE, "省份");
        nameArray.put(PickCateType.TYPE_CITY, "市区");
        nameArray.put(PickCateType.TYPE_DISTANCE, "距离");
        mLeftDialog2 = new PickChooseLeftDialog2(getContext(), nameArray);
        mLeftDialog2.setCallBack(this);
    }

    /**
     * 添加数据到中数据聚合
     */
    private void refreshDataInfo(int sort, String name, List<PickSelectEntity> children) {
        clearOtherDataInfo(sort);
        addEntity(sort, children);
    }

    /**
     * 清理关联项为空
     */
    private void clearOtherDataInfo(int sort) {
        switch (sort) {
            case PickCateType.TYPE_CATEGORY_0:
                addEntity(PickCateType.TYPE_CATEGORY_1, new ArrayList<>());
                addEntity(PickCateType.TYPE_CATEGORY_2, new ArrayList<>());
                break;
            case PickCateType.TYPE_CATEGORY_1:
                addEntity(PickCateType.TYPE_CATEGORY_2, new ArrayList<>());
                break;
            case PickCateType.TYPE_PROVINCE:
                addEntity(PickCateType.TYPE_CITY, new ArrayList<>());
                break;
        }
    }

    public void addEntity(int index, List<PickSelectEntity> list) {
        if (mData.get(index) != null) {
            if (list == null || list.size() == 0) {
                mData.get(index).setPickSelectEntityList(new ArrayList<>());
            } else {
                mData.get(index).setPickSelectEntityList(list);
            }
        } else {
            mData.put(index, new PickSelectTextEntity(index, nameArray.get(index), list));
        }
        mFilters.put(index, 0);
    }

    @Override
    public void loadCategory(PickSelectTextEntity entity, int itemPos) {
        List<PickSelectEntity> children = new ArrayList<>();
        if (itemPos > 0) {
            switch (entity.getSort()) {
                case PickCateType.TYPE_CATEGORY_0:
                    if (categoryDatas == null || categoryDatas.size() == 0) {
                        return;
                    }
                    List<PickSelectEntity<List<PickSelectEntity>>> cate1 = categoryDatas.get(itemPos).getChildren();
                    if (cate1 != null && cate1.size() > 0) {
                        children.addAll(cate1);
                    }
                    mLeftDialog2.clearOtherDataInfo(entity.getSort());
                    mLeftDialog2.addEntity(PickCateType.TYPE_CATEGORY_1, children);
                    mLeftDialog2.showDialog();
                    break;
                case PickCateType.TYPE_CATEGORY_1:
                    if (categoryDatas == null || categoryDatas.size() == 0) {
                        return;
                    }
                    int firPos = mLeftDialog2.getItemPos(0);
                    List<PickSelectEntity> cate2 = categoryDatas.get(firPos).getChildren().get(itemPos).getChildren();
                    if (cate2 != null && cate2.size() > 0) {
                        children.addAll(cate2);
                    }
                    mLeftDialog2.clearOtherDataInfo(entity.getSort());
                    mLeftDialog2.addEntity(PickCateType.TYPE_CATEGORY_2, children);
                    mLeftDialog2.showDialog();
                    break;
                case PickCateType.TYPE_PROVINCE:
                    model.getCityData(entity.getItemNo(itemPos), true);
                    break;
            }
        } else {
            if (entity.getSort() == PickCateType.TYPE_CATEGORY_0 || entity.getSort() == PickCateType.TYPE_CATEGORY_1 || entity.getSort() == PickCateType.TYPE_PROVINCE) {
                mLeftDialog2.clearOtherDataInfo(entity.getSort());
                mLeftDialog2.showDialog();
            }
        }

    }

    @Override
    public void loadData(SparseArray<PickSelectTextEntity> data, SparseIntArray map) {
        mData = PickCopyUtils.deepCopy(data);
        mFilters = map.clone();
        for (int i = 0; i < mData.size(); i++) {
            int key = mData.keyAt(i);
            PickSelectTextEntity entity = mData.get(key);
            updateChooseStatus(entity.getSort(), mFilters.get(entity.getSort()));
        }
        initFilterData();
    }

    @Override
    public void reset() {
        mFilters.clear();
        clearOtherDataInfo(PickCateType.TYPE_CATEGORY_0);
        clearOtherDataInfo(PickCateType.TYPE_PROVINCE);
        loadData(mData, mFilters);
        mLeftDialog2.initData(mData, mFilters);
        mLeftDialog2.showDialog();
    }

    @Override
    public void onCancel() {
        mLeftDialog2.initData(mData, mFilters);
    }

    /**
     * 获取当前缓存位置下标
     *
     * @param pos index
     */
    public int getItemPos(int pos) {
        return mFilters.get(pos);
    }

    public List<PickSelectEntity> getItemData(int index) {
        if (mData.get(index) != null) {
            return mData.get(index).getPickSelectEntityList();
        }
        return new ArrayList<>();
    }

    /**
     * 筛选赋值
     */
    private void updateChooseStatus(int key, int value) {
        mFilters.put(key, value);
        String no = mData.get(key).getItemNo(value);
        String name = mData.get(key).getItemName(value);
        switch (key) {
            case PickCateType.TYPE_CATEGORY_0:  //类别
                goodsType = no;
                if (TextUtils.isEmpty(no)) {
                    name = "类别";
                }
                updateChooseTextStatus(binding.tvCategory, value, name);
                break;
            case PickCateType.TYPE_CATEGORY_1:
            case PickCateType.TYPE_CATEGORY_2:
                if (!TextUtils.isEmpty(no)) {
                    goodsType = no;
                    if (value > 0) {
                        updateChooseTextStatus(binding.tvCategory, value, name);
                    }
                }
                break;
//            case PickCateType.TYPE_BIDDING: // 招标方式
//                tenderTypeNo = no;
//                updateChooseTextStatus(binding.tvType, value, name);
//                break;
            case PickCateType.TYPE_SIGN: // 报名方式
                tenderApplyNo = no;
                updateChooseTextStatus(binding.tvApply, value, name);
                break;
            case PickCateType.TYPE_BIDDING_STATUS: // 招标状态
                statusNo = no;
                updateChooseTextStatus(binding.tvStatus, value, name);
                break;
            case PickCateType.TYPE_MONEY: // 概算金额
                moneyNo = no;
                updateChooseTextStatus(binding.tvMoney, value, name);
                break;
            /*case PickCateType.TYPE_SIGN_TIME: // 报名结束时间
                time = no;
                updateChooseTextStatus(binding.tvTime, value, name);
                break;*/
            case PickCateType.TYPE_PROVINCE: // 省
                areacode = no;
                break;
            case PickCateType.TYPE_CITY: // 城市
                citysNo = no;
                break;
            case PickCateType.TYPE_DISTANCE: // 距离
                distance = no;
                break;
        }
    }

    /**
     * 更新选项颜色
     */
    private void updateChooseTextStatus(TextView textView, int value, String name) {
        if (!TextUtils.isEmpty(name)) {
            textView.setText(name);
        }
        if (value == -1) {
            setTextViewBg(textView, R.drawable.search_bg, R.mipmap.icon_up_red, R.color.color_tab_one);
        } else if (value == -2) {
            setTextViewBg(textView, R.drawable.search_new_blue_bg, R.mipmap.icon_up_red, R.color.color_main);
        } else if (value == 0) {
            setTextViewBg(textView, R.drawable.search_bg, R.mipmap.ic_down_arrow_n, R.color.color_tab_one);
        } else {
            setTextViewBg(textView, R.drawable.search_new_blue_bg, R.mipmap.icon_down_red, R.color.color_main);
        }
    }

    private void showChooseView(int tabPos) {
        if (tabPos == 0) {
            if (mData != null && mData.size() > 0 && mData.get(0) != null) {
                if (mData.get(0).getTypeName().contains("类别")) {
                    mData.remove(0);
                }
            }
        } else {
            resetCategoryFilterPopWindow();
        }
        if (isMap) {
            if (tabPos == 0) {
                binding.tvSort.setVisibility(View.GONE);
                binding.tvApply.setVisibility(View.VISIBLE);
                binding.tvStatus.setVisibility(View.VISIBLE);
                binding.tvDistance.setVisibility(View.VISIBLE);
            } else {
                binding.tvSort.setVisibility(View.GONE);
                binding.tvApply.setVisibility(View.GONE);
                binding.tvStatus.setVisibility(View.VISIBLE);
                binding.tvDistance.setVisibility(View.VISIBLE);
            }
        } else {
            if (tabPos == 0) {
                binding.tvSort.setVisibility(View.VISIBLE);
                binding.tvApply.setVisibility(View.VISIBLE);
                binding.tvStatus.setVisibility(View.VISIBLE);
                binding.tvDistance.setVisibility(View.GONE);
            } else {
                binding.tvSort.setVisibility(View.VISIBLE);
                binding.tvApply.setVisibility(View.GONE);
                binding.tvStatus.setVisibility(View.VISIBLE);
                binding.tvDistance.setVisibility(View.GONE);
            }
        }
    }

    public void getUrl(String url, String id) {
        WebViewX5HostActivity.start(getActivity(), url, id);
    }
}
